
import { _decorator, Component, Node, Graphics,EventTouch } from 'cc';
const { ccclass, property } = _decorator;

/**
 * Predefined variables
 * Name = Herojs
 * DateTime = Wed Apr 13 2022 20:25:16 GMT+0800 (中国标准时间)
 * Author = xiaopang125
 * FileBasename = Herojs.ts
 * FileBasenameNoExtension = Herojs
 * URL = db://assets/Herojs.ts
 * ManualUrl = https://docs.cocos.com/creator/3.4/manual/zh/
 *
 */

@ccclass('Herojs')
export class Herojs extends Component {
    // [1]
    // dummy = '';

    // [2]
    // @property
    // serializableDummy = 0;

    start() {
        // [3]

        // this.node.setPosition( 0,100,0);
      

        const g = this.getComponent(Graphics);
        g.lineWidth = 10;
        g.fillColor.fromHEX('#e98772');
        g.moveTo(-50, -50);
        g.lineTo(50, -50);
        g.lineTo(50, 50);
        g.lineTo(-50, 50);
        g.moveTo(-50, -50);
        g.close();
        g.stroke();
        g.fill();

        var _this=this;
        this.node.on(Node.EventType.TOUCH_START, function (e) {
            var pos = e.getLocation();
            console.log(pos);
        }, this)
        this.node.on(Node.EventType.TOUCH_MOVE,function(e){
            var delta = e.getDelta();
            var pos = e.getLocation();
            this.node.setPosition( this.node.position.x + delta.x, this.node.position.y + delta.y,0);
            //  this.node.setPosition( pos.x, pos.y,0);

 
            //  this.node.x+=delta.x;
            //  this.node.y+=delta.y;
    
           
            
            // console.log(this.node.position);
      },this);


    }


    // update (deltaTime: number) {
    //     // [4]
    // }
}

/**
 * [1] Class member could be defined like this.
 * [2] Use `property` decorator if your want the member to be serializable.
 * [3] Your initialization goes here.
 * [4] Your update function goes here.
 *
 * Learn more about scripting: https://docs.cocos.com/creator/3.4/manual/zh/scripting/
 * Learn more about CCClass: https://docs.cocos.com/creator/3.4/manual/zh/scripting/decorator.html
 * Learn more about life-cycle callbacks: https://docs.cocos.com/creator/3.4/manual/zh/scripting/life-cycle-callbacks.html
 */
